package com.sanen.flyer.entity.enemy;

import com.sanen.flyer.entity.Aircraft;
import com.sanen.flyer.entity.Bullet;
import com.sanen.flyer.entity.script.EmptySprit;

/**
 * @author wsse
 * @date 2018-09-07 10:45
 */
public abstract class Enemy extends Aircraft {
    protected EmptySprit sprit;

    @Override
    public boolean outOfBounds() {
        return false;
    }

    @Override
    public boolean touchBounds() {
        return false;
    }

    public boolean byHit(Bullet o) {
        if (x + width - paddingR < o.getX() + o.getPaddingL() || x + paddingL > o.getX() + o.getWidth() - o.getPaddingR()
                || y + height - paddingB < o.getY() + o.getPaddingT() || y + paddingT > o.getY() + o.getHeight() - o.getPaddingB()) {
            return false;
        }
        hp-=o.getAp();
        if(hp<=0)isRemove=true;
        sprit.byHit();
        return true;
    }

    @Override
    public void move() {
            y += (int) speedy;
            sumy += speedy - (int) (speedy);
            x += (int) speedx;
            sumx += speedx - (int) speedx;


        if (sumy >= 1) {
            y += 1;
            sumy--;
        } else if (sumy <= -1) {
            y -= 1;
            sumy++;
        }
        if (sumx >= 1) {
            this.x += 1;
            sumx--;
        } else if (sumx <= -1) {
            x -= 1;
            sumx++;
        }
    }
}
